<?php
//decode by QQ:735674691 http://bbs.yaoduoli.com/

if (!defined('INDEX')) {
    exit('Access Denied');
}
function act_wap_goods2(){
	global $duoduo,$dd_tpl_data;
	$webset = $duoduo->webset;
	$dduser = $duoduo->dduser;
	
	include(DDROOT.'/comm/goods.class.php');
	$goods_class=new goods($duoduo);
	
	$page=$_GET['page']?$_GET['page']:1;
	$code=$_GET['code'];
	$cid=(int)$_GET['cid'];
	$pagesize=10;
	$fromnum=($page-1)*$pagesize;
	
	$bankuai=dd_get_cache('bankuai');
	$where='1';
	$title='全部商品';
    $q=$_GET['q'];
	if($q!=''){
		$where.=' and title like "%'.$q.'%"';
	}
	
	if($code!=''){
		$where.=' and code="'.$code.'"';
		$title=$bankuai[$code]['title'];
	}
	if($cid>0){
		$where.=' and cid="'.$cid.'"';
		$title=$bankuai[$code]['title'];
	}

	$shuju_data=$goods_class->index_list(array('code'=>$code),$pagesize,$page,'(laiyuan_type in(1,2) or domain="jd.com") and '.$where);
	foreach($shuju_data as $k=>$row){
	if($row['is_new']){
	$shuju_data[$k]['xin']='<span class="xinpin"></span>>';
	 }
	 else{
	 $shuju_data[$k]['xin']='';
	 }
	if($row['price_man']>0){
	 $shuju_data[$k]['quan_hou']='<span class="title-tips01">券后</span>';
	 $shuju_data[$k]['youhuiquan']='<a href="'.$row['lq_url'].'"><div class="quan_img"><span class="num_money left">'.$row['price_jian'].'</span></div></a>';
	 }
	 else{
	 $shuju_data[$k]['quan_hou']='';
	 $shuju_data[$k]['youhuiquan']='';
	 }
	 if($row['quan_total']>0){
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price']-$row['price_jian'].'';
	 $shuju_data[$k]['quanhoufan']=''.number_format((($row['discount_price']-$row['price_jian'])*$row['fanli_bl']/100),2).'';
	 }else{
	 $shuju_data[$k]['quanhoujia']=''.$row['discount_price'].'';
	 $shuju_data[$k]['quanhoufan']=''.number_format((($row['discount_price'])*$row['fanli_bl']/100),2).'';
	 }
					
		if($row['id']){
			$shuju_data[$k]['url']=wap_l('goods','view',array('id'=>$row['id'],'rec'=>$dduser['id']));
		}
		else{
			$shuju_data[$k]['url']=wap_l('goods','view',array('iid'=>$row['data_id'],'rec'=>$dduser['id']));
		}
		$shuju_data[$k]['bankuai_title']=$bankuai[$row['code']]['title'];
		$shuju_data[$k]['img']=tb_img($row['img'],500);
		$shuju_data[$k]['quan_price']=$row['discount_price']-$row['price_jian'];
	}
	 
	if(AJAX==1){
		echo dd_json_encode(array('s'=>1,'r'=>$shuju_data));
		dd_exit();
	}

	$parameter['shuju_data']=$shuju_data;
	$parameter['code']=$code;
	$parameter['title']=$bankuai[$code]['title'];
	$parameter['webtitle']=$title.'-首页';
	$parameter['q']=$q.'';
	unset($duoduo);
	unset($webset);
	unset($dduser);
	unset($dd_tpl_data);
	return $parameter;
}